package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.IotEnterprise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2020-10-05 16:34:02
 */
@Repository
public class IotEnterpriseDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(IotEnterpriseDao.class);

    public IotEnterprise insert(final IotEnterprise iotEnterprise) {
        insert("IotEnterprise.insert", iotEnterprise);
        return iotEnterprise;
    }

    public Boolean updateInfoById(final IotEnterprise iotEnterprise) {
        return update("IotEnterprise.updateInfoById", iotEnterprise) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("IotEnterprise.updateInfoByQuery", query) > 0;
    }

    public IotEnterprise selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("IotEnterprise.selectById", query);
    }

    public List<IotEnterprise> selectByQuery(final Query query) {
        return queryForList("IotEnterprise.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("IotEnterprise.countByQuery", query);
    }

    public Boolean deleteById(final Integer id) {
        IotEnterprise iotEnterprise = new IotEnterprise();
        iotEnterprise.setDeleteFlag(1);
        iotEnterprise.setId(id);

        return update("IotEnterprise.updateInfoById", iotEnterprise) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("IotEnterprise.deleteById", query) > 0;
    }
}